/*
@Time : 2022/7/13 17:16
@Author : gaozhichang
@File : main.go
@des: GoLand
*/
package main

import (
	"context"
	"fmt"
	//"github.com/olivere/elastic"
	"github.com/olivere/elastic/v7"
)

func init() {
	//client,err := elastic.NewClient()

}

type User struct {
	Name string `json:"name"`
	Age int `json:"age"`
	Des string `json:"des"`
}


func main()  {
	// 创建ES client用于后续操作ES
	client, err := elastic.NewClient(
		// 设置ES服务地址，支持多个地址
		elastic.SetURL("http://10.21.134.59:8200/", "http://10.21.134.63:8200/"),
		// 设置基于http base auth验证的账号和密码
		//elastic.SetBasicAuth("user", "secret")
		)
	if err != nil {
		// Handle error
		fmt.Printf("连接失败: %v\n", err)
	} else {
		fmt.Println("连接成功")
	}
	fmt.Println(client)

	u3 := &User{
		Name: "qiqi",
		Age:  10,
		Des:  "爱跳芭蕾",
	}
	put, err:=client.Index().Index("ai-helpage").Type("user").BodyJson(u3).Do(context.Background())
	if err != nil {
		fmt.Println(fmt.Sprintf("put err:%v", err))
		return
	}
	fmt.Println(put)
	fmt.Println("done")
}

